package com.wlc.base.jichu;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 测试
 * @date 2021-09-02 09:07
 */
public class Demo11 extends Demo01 implements Serializable {

    private static final long serialVersionUID = -193742444550410549L;

    public static void main(String[] args) {
        method06();
    }


    public static void method05() {
        int a = 2;
        if (a == 3 | a == 2) {
            System.out.println("hello");
        }
        System.out.println("m");
    }

    public Demo11() {

        System.out.println("默认的构造方法");
    }

    public Demo11(String name) {
        this();
        System.out.println("狗子" + name + " 丢了");
    }

    public static void method06() {
       new Demo11("打包");
    }

    public static void method04() {
        System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")));

    }

    public static void method02() {
        List<String> list = new ArrayList<String>();
        list.add("a");
        list.add("a");
        list.add("a");
        list.add("b");
        list.add("b");
        list.add("c");
        System.out.println("没有去重前的数据为>>>" + list.toString());
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                if (list.get(j).equals(list.get(i))) {
                    list.remove(j);
                }
            }
        }
        System.out.println("去重后的数据为>>>" + list.toString());
    }

    public static void method03() {
        List<String> list = new ArrayList<String>();
        list.add("a");
        list.add("a");
        list.add("a");
        list.add("b");
        list.add("b");
        list.add("c");
        System.out.println("没有去重前的数据为>>>" + list.toString());
        // 2 把list 数据放入到 HashSet 中，因为HashSet 是不允许重复的
        HashSet set = new HashSet(list);
        System.out.println("set.toString() = " + set.toString());
        // 3.使用jdk1.8中的 distinct()可以快速的去重
        List<String> list1 = list.stream().distinct().collect(Collectors.toList());
        System.out.println("list1 = " + list1);
    }

    public static void method01() {
        // 总共50瓶，喝三瓶可以赠一瓶，总共需要喝多少瓶
        int n = 50;
        int i = 0;
        int a = 0;
        while (true) {
            n -= 3;
            a += 3;
            i++;
            if (n < 3) {
                System.out.println("总共喝了" + (a + i) + "瓶");
                break;
            }
        }
    }
}
